/**
 * 
 */
package com.yst.metho.web.application.user.renderer;

import nextapp.echo2.app.Component;
import nextapp.echo2.app.Label;
import nextapp.echo2.app.Table;
import nextapp.echo2.app.table.TableCellRenderer;

import com.yst.suivi.data.user.User;

/**
 * @author perso
 * 
 */
public class UserTableCellRenderer implements TableCellRenderer
{

	private static final int FIRM_COLUMN = 3;

	private static final int FIRST_NAME_COLUMN = 2;

	private static final int NAME_COLUMN = 1;

	private static final int LOGIN_COLUMN = 0;

	private String decorate(User usr, String text)
	{
		String retour;
		if (null == usr.getEndDate())
		{
			retour = text;
		}
		else
		{
			retour = text + " *";
		}
		return retour;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
	 *      java.lang.Object, int, int)
	 */
	public Component getTableCellRendererComponent(Table table, Object value, int column, int row)
	{
		User usr = (User) value;
		Label label = new Label("");
		if (null != value)
		{

			switch (column)
			{
			case LOGIN_COLUMN:
				label.setText(decorate(usr, usr.getLogin()));
				break;
			case NAME_COLUMN:
				label.setText(usr.getNom());
				break;
			case FIRST_NAME_COLUMN:
				label.setText(usr.getPrenom());
				break;
			case FIRM_COLUMN:
				label.setText(usr.getSociete());
				break;
			default:
				label.setText("colonne inconnu : " + column);
			}
		}
		else
		{
			label.setText("null");
		}
		if (row % 2 == 0)
		{
			label.setStyleName("ListingView.EvenRowLabel");
		}
		else
		{
			label.setStyleName("ListingView.OddRowLabel");
		}
		return label;
	}

}
